package com.ql.controller;

import com.ql.domain.response.JsonResult;
import com.ql.domain.Project;
import com.ql.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    ProjectService projectService;

    @RequestMapping("/findAll.do")
    @ResponseBody
    public JsonResult findAll(String projectName, @RequestParam(name = "page", required = true, defaultValue = "1") Integer page, @RequestParam(name = "limit", required = true, defaultValue = "10") Integer limit) {
        return projectService.findAll(projectName, page, limit);
    }

    @RequestMapping("/save.do")
    @ResponseBody
    public JsonResult save(Project project) {
        return projectService.save(project);
    }

    @RequestMapping("/update.do")
    @ResponseBody
    public JsonResult update(Project project) {
        return projectService.update(project);
    }

    @RequestMapping("/del.do")
    @ResponseBody
    public JsonResult del(String id) {
        return projectService.del(id);
    }

    //获取账户所在的项目
    @RequestMapping("/projectGroupName.do")
    @ResponseBody
    public List<Project> projectGroupName(String[] projectIds) {
        return projectService.projectGroupName(projectIds);
    }

    //获取所有项目
    @RequestMapping("/allProjectGroupName.do")
    @ResponseBody
    public List<Project> allProjectGroupName() {
        return projectService.allProjectGroupName();
    }
}
